import axios from "axios";

const state ={
    adminName:localStorage.adminName,
    token:localStorage.token,
    status:localStorage.status?JSON.parse(localStorage.status):'',
    adminLog:[]
}
const mutations = {
    CHANGE_LOGIN_INFO(state,info){
        state.adminName = localStorage.adminName =  info.adminName;
        state.token = localStorage.token = info.token;
        state.status=localStorage.status=info.status;
        // console.log(typeof(state.status))
    },
    OUT_LOGIN(state){
        localStorage.clear();
        state.adminName = state.token = null;
        state.status="";
    },
    CHANGE_ADMIN_LOG(state,adminLog){
        state.adminLog = adminLog;
    }
}
const actions = {
    async login({commit},params){
        const data = await axios.post("/login",params);
        // console.log(data)
        return data;
        
    },
    async getAdminLog({commit},query={}){
        const {pageIndex = 1} = query;
        const data = await axios.get("/adminLog",{
            params:{
                pageIndex
            }
        });
        commit("CHANGE_ADMIN_LOG",data.adminLog);
        return data;
    }
}
export default {
    state,
    actions,
    mutations
}